home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 April: Mac OS SDK / Dev.CD Apr 99 SDK1.toast / Development Kits / Mac OS USB DDK / Examples / KeyboardModule / KeyboardModuleHeader.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-10  |  5.3 KB  |  161 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        KeyboardModuleHeader.c
  3.  
  4.     Contains:    Keyboard Module Header file
  5.  
  6.     Version:    xxx put version here xxx
  7.  
  8.     Copyright:    © 1997-1999 by Apple Computer, Inc., all rights reserved.
  9.  
  10. */
  11.  
  12. #include <Types.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <USB.h>
  16.  
  17. #include "KeyboardModule.h"
  18. #include "KeyboardModuleVersion.h"
  19.  
  20. static     OSStatus     KeyboardModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable);
  21. static     OSStatus     KeyboardModuleFinalize(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  22. static     OSStatus     KeyboardInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device);
  23. static    OSStatus    KeyboardNotifyProc(UInt32     notification, void *pointer, UInt32 refcon);
  24.  
  25. extern    usbKeyboardPBStruct myKeyboardPB;
  26. extern    usbKeyboardPBStruct shimKeyboardPB;
  27.  
  28. //------------------------------------------------------
  29. //
  30. //    This is the driver description structure that the expert looks for first.
  31. //  If it's here, the information within is used to match the driver
  32. //  to the device whose descriptor was passed to the expert.
  33. //    Information in this block is also used by the expert when an
  34. //  entry is created in the Name Registry.
  35. //
  36. //------------------------------------------------------
  37. USBDriverDescription    TheUSBDriverDescription = 
  38. {
  39.     // Signature info
  40.     kTheUSBDriverDescriptionSignature,
  41.     kInitialUSBDriverDescriptor,
  42.     
  43.     // Device Info
  44.     0,                                        // vendor = not device specific
  45.     0,                                        // product = not device specific
  46.     0,                                        // version of product = not device specific
  47.     kUSBKeyboardInterfaceProtocol,            // protocol = not device specific
  48.     
  49.     // Interface Info    (* I don't think this would always be required...*)                
  50.     0,                                        // Configuration Value
  51.     0,                                        // Interface Number
  52.     kUSBHIDInterfaceClass,                    // Interface Class
  53.     kUSBBootInterfaceSubClass,                 // Interface SubClass
  54.     kUSBKeyboardInterfaceProtocol,                // Interface Protocol
  55.         
  56.     
  57.     // Driver Info
  58.     kKeyboardModuleName kKBDStringVersShort,    // Driver name for Name Registry
  59.     kUSBHIDInterfaceClass,                        // Device Class  (from USBDeviceDefines.h)
  60.     kUSBBootInterfaceSubClass,                    // Device Subclass 
  61.     kKBDHexMajorVers, 
  62.     kKBDHexMinorVers, 
  63.     kKBDCurrentRelease, 
  64.     kKBDReleaseStage,                        // version of driver
  65.     
  66.     // Driver Loading Info
  67.     kUSBProtocolMustMatch                    // Flags 
  68. };
  69.  
  70. USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
  71. {
  72.     kClassDriverPluginVersion,                // Version of this structure
  73.     0,                                        // Hardware Validation Procedure
  74.     KeyboardModuleInitialize,                // Initialization Procedure
  75.     KeyboardInterfaceInitialize,            // Interface Initialization Procedure
  76.     KeyboardModuleFinalize,                    // Finalization Procedure
  77.     KeyboardNotifyProc,                        // Driver Notification Procedure
  78. };
  79.     
  80.     
  81. // Initialization function
  82. // Called upon load by Expert
  83. static     OSStatus     KeyboardModuleInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
  84. {
  85. #pragma unused (busPowerAvailable)
  86. #pragma unused (pDesc)
  87.     USBExpertStatus(device, kKeyboardModuleName": Entered via KeyboardModuleInitialize", device);
  88.     return (OSStatus)noErr;
  89. }
  90.  
  91. // Interface Initialization Initialization function
  92. // Called upon load by Expert
  93. static     OSStatus     KeyboardInterfaceInitialize (UInt32 interfacenum, USBInterfaceDescriptorPtr pInterface, USBDeviceDescriptorPtr pDesc, USBDeviceRef device)
  94. {
  95.     InterfaceEntry(interfacenum, pInterface, pDesc, device);
  96.     return (OSStatus)noErr;
  97. }
  98.  
  99. static OSStatus    KeyboardNotifyProc(UInt32     notification, void *pointer, UInt32 refcon)
  100. {
  101. #pragma unused (pointer)
  102. #pragma unused (refcon)
  103.  
  104. OSStatus    status = noErr;
  105.  
  106.     switch (notification)
  107.     {
  108.         case kNotifyDriverBeingRemoved:
  109.             shimKeyboardPB.driverRemovalPending = true;
  110.             myKeyboardPB.driverRemovalPending = true;
  111.             
  112.             shimKeyboardPB.keyboardReady = false;
  113.             myKeyboardPB.keyboardReady = false;
  114.             
  115.             USBExpertStatus(myKeyboardPB.interfaceRef, kKeyboardModuleName": Notification that driver removal is pending...", notification);
  116.  
  117.             if ((shimKeyboardPB.pb.usbRefcon & kCompletionPending) ||
  118.                 (myKeyboardPB.pb.usbRefcon & kCompletionPending))
  119.             {
  120.                 if (shimKeyboardPB.pb.usbRefcon & kCompletionPending)
  121.                 {
  122.                     USBExpertStatus(myKeyboardPB.interfaceRef, kKeyboardModuleName": Waiting for set LEDs transaction to complete", myKeyboardPB.pb.usbRefcon);
  123.                 }
  124.                 
  125.                 if (myKeyboardPB.pb.usbRefcon & kCompletionPending)
  126.                 {
  127.                     USBExpertStatus(myKeyboardPB.interfaceRef, kKeyboardModuleName": Waiting for normal transaction to complete", myKeyboardPB.pb.usbRefcon);
  128.                 }
  129.                 
  130.                 if (myKeyboardPB.pipeRef)
  131.                 {
  132.                     USBExpertStatus(myKeyboardPB.interfaceRef, kKeyboardModuleName": Aborting interrupt pipe", myKeyboardPB.pipeRef);
  133.                     if (USBAbortPipeByReference(myKeyboardPB.pipeRef) != noErr){
  134.                         myKeyboardPB.pb.usbRefcon &=  ~kCompletionPending;   // don't expect the completion to be called either
  135.                     }
  136.                     myKeyboardPB.intPipeAborted = true;
  137.                     myKeyboardPB.pipeRef = nil;
  138.                 }
  139.                 status = kUSBDeviceBusy;
  140.             }
  141.             break;
  142.             
  143.         default:
  144.             break;
  145.     } // switch
  146.     
  147.     
  148.     return(status);
  149. }
  150.  
  151. // Termination function
  152. // Called by Expert when driver is being shut down
  153. static OSStatus KeyboardModuleFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
  154. {
  155. #pragma unused (pDesc)
  156.  
  157.     USBExpertStatus(theDeviceRef, kKeyboardModuleName": Finalize", theDeviceRef);
  158.     return (OSStatus)noErr;
  159. }
  160.  
  161.